package org.acghub.mtdb.core;

import java.util.ArrayDeque;
import java.util.Deque;

public final class LogNotify {
    private final Deque<LogKey> stack = new ArrayDeque<>();

    private final Note note;

    private LogNotify(LogKey logkey, Note note) {
        stack.add(logkey);
        this.note = note;
    }

    public static void notify(LogKey logkey, Note note) {
        logkey.getBean().notify(new LogNotify(logkey, note));
    }

    boolean isEmpty() {
        return stack.isEmpty();
    }

    LogKey pop() {
        return stack.pop();
    }

    LogNotify push(LogKey logkey) {
        stack.push(logkey);
        return this;
    }

    Note getNote() {
        return note;
    }

    @Override
    public String toString() {
        StringBuilder sb = new StringBuilder();
        for (LogKey logKey : stack) {
            sb.append('.').append(logKey.getVarname());
        }
        sb.append('=').append(note);
        return sb.toString();
    }
}
